﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PlatypusPlanner.Components.Database;
using System.Web;


namespace PlatypusPlanner.Components.Base
{
    public static class EntityContextController
    {
        public static PlatypusEntities GetContext()
        {
            if (!HttpContext.Current.Items.Contains(Globals.ObjectContextKey))
                HttpContext.Current.Items.Add(Globals.ObjectContextKey, new PlatypusEntities());

            return HttpContext.Current.Items[Globals.ObjectContextKey] as PlatypusEntities;
        }
        public static void DisposeContext()
        {
            if (HttpContext.Current.Items.Contains(Globals.ObjectContextKey))
            {
                PlatypusEntities entityContext = HttpContext.Current.Items[Globals.ObjectContextKey] as PlatypusEntities;
                if (entityContext != null)
                    entityContext.Dispose();

                HttpContext.Current.Items.Remove(Globals.ObjectContextKey);
            }
        }
    }
}
